MifareClassic 您所在的位置:网站首页 非mifare classic标签! MifareClassic

MifareClassic

2024-06-03 21:25| 来源: 网络整理| 查看: 265

MifareClassic

public final class MifareClassic extends Object implements TagTechnology

java.lang.Object    ↳ android.nfc.tech.MifareClassic

提供对 Tag MIFARE Classic属性和I / O操作的 Tag 。

使用 get(Tag)获取 MifareClassic对象。

MIFARE Classic也被称为MIFARE标准。

MIFARE Classic标签分为多个扇区,每个扇区被细分为多个块。 块大小始终为16个字节( BLOCK_SIZE 。扇区大小各不相同。

MIFARE Classic Mini are 320 bytes (SIZE_MINI), with 5 sectors each of 4 blocks. MIFARE Classic 1k are 1024 bytes (SIZE_1K), with 16 sectors each of 4 blocks. MIFARE Classic 2k are 2048 bytes (SIZE_2K), with 32 sectors each of 4 blocks. MIFARE Classic 4k} are 4096 bytes (SIZE_4K). The first 32 sectors contain 4 blocks and the last 8 sectors contain 16 blocks.

在执行该扇区上的任何其他I / O操作之前,MIFARE Classic标签需要按扇区进行身份验证。 每个扇区有两个密钥,ACL位在使用密钥进行身份验证之后确定该扇区允许哪些I / O操作。 和。

三大知名认证密钥在这个类中定义: KEY_DEFAULT , KEY_MIFARE_APPLICATION_DIRECTORY , KEY_NFC_FORUM 。

KEY_DEFAULT is the default factory key for MIFARE Classic. KEY_MIFARE_APPLICATION_DIRECTORY is the well-known key for MIFARE Classic cards that have been formatted according to the MIFARE Application Directory (MAD) specification. KEY_NFC_FORUM is the well-known key for MIFARE Classic cards that have been formatted according to the NXP specification for NDEF on MIFARE Classic.

在Android NFC设备上实现此类是可选的。 如果它没有实现,那么MifareClassic将永远不会在getTechList()枚举。 如果枚举,则将支持所有MifareClassic I / O操作,并且还将支持MIFARE_CLASSIC NDEF标记。 无论哪种情况, NfcA也将枚举在标签上,因为所有MIFARE Classic标签也都是NfcA 。

注意:执行I / O操作的方法需要 NFC权限。

也可以看看:

authenticateSectorWithKeyA(int, byte[]) authenticateSectorWithKeyB(int, byte[]) Summary Constants int BLOCK_SIZE

MIFARE Classic块的大小(以字节为单位)

int SIZE_1K

标签包含16个扇区,每个扇区有4个块。

int SIZE_2K

标签包含32个扇区,每个扇区有4个块。

int SIZE_4K

标签包含40个扇区。

int SIZE_MINI

标签包含5个扇区,每个扇区有4个块。

int TYPE_CLASSIC

MIFARE经典标签

int TYPE_PLUS

MIFARE Plus标签

int TYPE_PRO

MIFARE Pro标签

int TYPE_UNKNOWN

未知类型的MIFARE Classic兼容卡

Fields public static final byte[] KEY_DEFAULT

默认的工厂密钥。

public static final byte[] KEY_MIFARE_APPLICATION_DIRECTORY

众所周知的按照MIFARE应用程序目录(MAD)规范格式化的标签密钥。

public static final byte[] KEY_NFC_FORUM

在MIFARE Classic规范中根据NDEF格式化标签的着名密钥。

Public methods boolean authenticateSectorWithKeyA(int sectorIndex, byte[] key)

使用密钥A对扇区进行身份验证

boolean authenticateSectorWithKeyB(int sectorIndex, byte[] key)

使用密钥B对扇区进行身份验证

int blockToSector(int blockIndex)

返回包含给定块的扇区。

void close()

禁用对来自此 TagTechnology对象的标记的I / O操作,并释放资源。

void connect()

对来自此 TagTechnology对象的标记启用I / O操作。

void decrement(int blockIndex, int value)

减量值块,将结果存储在标签上的临时块中。

static MifareClassic get(Tag tag)

为给定标签获取 MifareClassic的实例。

int getBlockCount()

返回MIFARE Classic块的总数。

int getBlockCountInSector(int sectorIndex)

返回给定扇区中的块数。

int getMaxTransceiveLength()

返回可用 transceive(byte[])发送的最大字节数。

int getSectorCount()

返回MIFARE Classic扇区的数量。

int getSize()

以字节为单位返回标签的大小

一个 SIZE_MINI , SIZE_1K , SIZE_2K , SIZE_4K 。

Tag getTag()

获取 Tag对象支持此 TagTechnology对象。

int getTimeout()

以毫秒为单位获取当前的 transceive(byte[])超时。

int getType()

返回此MIFARE Classic兼容标签的类型。

void increment(int blockIndex, int value)

增加一个值块,将结果存储在标签上的临时块中。

boolean isConnected()

帮助者指出I / O操作是否可行。

byte[] readBlock(int blockIndex)

读取16个字节的块。

void restore(int blockIndex)

从值块复制到临时块。

int sectorToBlock(int sectorIndex)

返回给定扇区的第一个块。

void setTimeout(int timeout)

以毫秒为单位设置 transceive(byte[])超时。

byte[] transceive(byte[] data)

将原始NfcA数据发送到标签并接收响应。

void transfer(int blockIndex)

从临时块复制到值块。

void writeBlock(int blockIndex, byte[] data)

写16个字节的块。

Inherited methods From class java.lang.Object Object clone()

创建并返回此对象的副本。

boolean equals(Object obj)

指示其他某个对象是否“等于”这一个。

void finalize()

当垃圾收集确定没有更多对该对象的引用时,由对象上的垃圾回收器调用。

final Class getClass()

返回此 Object的运行时类。

int hashCode()

返回对象的哈希码值。

final void notify()

唤醒正在等待该对象监视器的单个线程。

final void notifyAll()

唤醒在该对象监视器上等待的所有线程。

String toString()

返回对象的字符串表示形式。

final void wait(long millis, int nanos)

导致当前线程等待,直到另一个线程为该对象调用 notify()方法或 notifyAll()方法,或者某个其他线程中断当前线程,或经过一定的实时时间。

final void wait(long millis)

导致当前线程等待,直到另一个线程调用此对象的 notify()方法或 notifyAll()方法或经过了指定的时间量。

final void wait()

导致当前线程等待,直到另一个线程调用此对象的 notify()方法或 notifyAll()方法。

From interface android.nfc.tech.TagTechnology abstract void close()

禁用对来自此 TagTechnology对象的标记的I / O操作,并释放资源。

abstract void connect()

启用来自此 TagTechnology对象的标记的I / O操作。

abstract Tag getTag()

获取 Tag对象支持此 TagTechnology对象。

abstract boolean isConnected()

帮助者指出I / O操作是否可行。

From interface java.io.Closeable abstract void close()

关闭此流并释放与其关联的所有系统资源。

From interface java.lang.AutoCloseable abstract void close()

关闭此资源,放弃任何底层资源。

Constants BLOCK_SIZE Added in API level 10 int BLOCK_SIZE

MIFARE Classic块的大小(以字节为单位)

常量值:16(0x00000010)

SIZE_1K Added in API level 10 int SIZE_1K

标签包含16个扇区,每个扇区有4个块。

常量值:1024(0x00000400)

SIZE_2K Added in API level 10 int SIZE_2K

标签包含32个扇区,每个扇区有4个块。

常量值:2048(0x00000800)

SIZE_4K Added in API level 10 int SIZE_4K

标签包含40个扇区。 前32个扇区包含4个块,最后8个扇区包含16个块。

常量值:4096(0x00001000)

SIZE_MINI Added in API level 10 int SIZE_MINI

标签包含5个扇区,每个扇区有4个块。

常量值:320(0x00000140)

TYPE_CLASSIC Added in API level 10 int TYPE_CLASSIC

MIFARE经典标签

常量值:0(0x00000000)

TYPE_PLUS Added in API level 10 int TYPE_PLUS

MIFARE Plus标签

常数值:1(0x00000001)

TYPE_PRO Added in API level 10 int TYPE_PRO

MIFARE Pro标签

常量值:2(0x00000002)

TYPE_UNKNOWN Added in API level 10 int TYPE_UNKNOWN

未知类型的MIFARE Classic兼容卡

常量值:-1(0xffffffff)

Fields KEY_DEFAULT Added in API level 10 byte[] KEY_DEFAULT

默认的工厂密钥。

KEY_MIFARE_APPLICATION_DIRECTORY Added in API level 10 byte[] KEY_MIFARE_APPLICATION_DIRECTORY

众所周知的按照MIFARE应用程序目录(MAD)规范格式化的标签密钥。

KEY_NFC_FORUM Added in API level 10 byte[] KEY_NFC_FORUM

在MIFARE Classic规范中根据NDEF格式化标签的着名密钥。

Public methods authenticateSectorWithKeyA Added in API level 10 boolean authenticateSectorWithKeyA (int sectorIndex, byte[] key)

使用密钥A对扇区进行身份验证

使用密钥A对扇区进行成功验证可以启用该扇区上的其他I / O操作。 由A密钥授予的操作集取决于在该扇区中设置的ACL位。 欲了解更多信息,请参阅MIFARE Classic规范。

认证尝试失败会导致标签隐式重新连接,因此对其他扇区的认证将会丢失。

这是一个I / O操作,将阻塞直到完成。 它不能从主应用程序线程调用。 如果从另一个线程调用close()被阻止的呼叫将被取消, IOException 。

需要 NFC权限。

Parameters sectorIndex int: index of sector to authenticate, starting from 0 key byte: 6-byte authentication key Returns boolean true on success, false on authentication failure Throws TagLostException if the tag leaves the field IOException if there is an I/O failure, or the operation is canceled

也可以看看:

ERROR(/http://www.nxp.com) authenticateSectorWithKeyB Added in API level 10 boolean authenticateSectorWithKeyB (int sectorIndex, byte[] key)

使用密钥B对扇区进行身份验证

使用密钥B对扇区进行成功验证可启用该扇区上的其他I / O操作。 由密钥B授予的一组操作取决于在该扇区中设置的ACL位。 欲了解更多信息,请参阅MIFARE Classic规范。

认证尝试失败会导致标签隐式重新连接,因此对其他扇区的认证将会丢失。

这是一个I / O操作,将阻塞直到完成。 它不能从主应用程序线程调用。 如果从另一个线程调用close()被阻止的呼叫将被IOException取消。

需要 NFC权限。

Parameters sectorIndex int: index of sector to authenticate, starting from 0 key byte: 6-byte authentication key Returns boolean true on success, false on authentication failure Throws TagLostException if the tag leaves the field IOException if there is an I/O failure, or the operation is canceled

也可以看看:

ERROR(/http://www.nxp.com) blockToSector Added in API level 10 int blockToSector (int blockIndex)

返回包含给定块的扇区。

不会导致任何RF活动并且不会阻止。

Parameters blockIndex int: index of block to lookup, starting from 0 Returns int sector index that contains the block close Added in API level 10 void close ()

禁用对来自此 TagTechnology对象的标记的I / O操作,并释放资源。

还会导致其他线程上的所有被阻止的I / O操作被取消,并返回 IOException 。

需要 NFC权限。

Throws IOException connect Added in API level 10 void connect ()

对来自此 TagTechnology对象的标记启用I / O操作。

可能导致RF活动并可能阻塞。 不能从主应用程序线程调用。 IOException通过从另一个线程调用close()来取消被阻止的呼叫。

一次只能将一个 TagTechnology对象连接到 Tag 。

当I / O操作完成时,应用程序必须调用 close() 。

需要 NFC权限。

Throws IOException decrement Added in API level 10 void decrement (int blockIndex, int value)

减量值块,将结果存储在标签上的临时块中。

这是一个I / O操作,将阻塞直到完成。 它不能从主应用程序线程调用。 如果从另一个线程调用close()被阻止的呼叫将被取消, IOException 。

需要 NFC权限。

Parameters blockIndex int: index of block to decrement, starting from 0 value int: non-negative to decrement by Throws TagLostException if the tag leaves the field IOException if there is an I/O failure, or the operation is canceled get Added in API level 10 MifareClassic get (Tag tag)

获取给定标签的 MifareClassic实例。

不会导致任何RF活动并且不会阻止。

如果MifareClassic未在getTechList()枚举,则返回null。 这表明该标签不是MIFARE Classic兼容的,或者该Android设备不支持MIFARE Classic。

Parameters tag Tag: an MIFARE Classic compatible tag Returns MifareClassic MIFARE Classic object getBlockCount Added in API level 10 int getBlockCount ()

返回MIFARE Classic块的总数。

不会导致任何RF活动并且不会阻止。

Returns int total number of blocks getBlockCountInSector Added in API level 10 int getBlockCountInSector (int sectorIndex)

返回给定扇区中的块数。

不会导致任何RF活动并且不会阻止。

Parameters sectorIndex int: index of sector, starting from 0 Returns int number of blocks in the sector getMaxTransceiveLength Added in API level 14 int getMaxTransceiveLength ()

返回可以通过 transceive(byte[])发送的最大字节数。

Returns int the maximum number of bytes that can be sent with transceive(byte[]). getSectorCount Added in API level 10 int getSectorCount ()

返回MIFARE Classic扇区的数量。

不会导致任何RF活动并且不会阻止。

Returns int number of sectors getSize Added in API level 10 int getSize ()

以字节为单位返回标签的大小

一个SIZE_MINI , SIZE_1K , SIZE_2K , SIZE_4K 。 这些常量等于它们各自的字节大小。

不会导致任何RF活动并且不会阻止。

Returns int size in bytes getTag Added in API level 10 Tag getTag ()

获取 Tag对象支持此 TagTechnology对象。

Returns Tag the Tag backing this TagTechnology object. getTimeout Added in API level 14 int getTimeout ()

以毫秒为单位获取当前的 transceive(byte[])超时。

需要 NFC权限。

Returns int timeout value in milliseconds getType Added in API level 10 int getType ()

返回此MIFARE Classic兼容标签的类型。

一个 TYPE_UNKNOWN , TYPE_CLASSIC , TYPE_PLUS或者 TYPE_PRO 。

不会导致任何RF活动并且不会阻止。

Returns int type increment Added in API level 10 void increment (int blockIndex, int value)

增加一个值块,将结果存储在标签上的临时块中。

这是一个I / O操作,将阻塞直到完成。 它不能从主应用程序线程调用。 如果从另一个线程调用close()被阻止的呼叫将被IOException取消。

需要 NFC权限。

Parameters blockIndex int: index of block to increment, starting from 0 value int: non-negative to increment by Throws TagLostException if the tag leaves the field IOException if there is an I/O failure, or the operation is canceled isConnected Added in API level 10 boolean isConnected ()

帮助者指出I / O操作是否可行。

如果返回true connect()已经完成,并 close()没有被调用,并且 Tag不知道是超出范围。

不会导致射频活动,也不会阻止。

Returns boolean true if I/O operations should be possible readBlock Added in API level 10 byte[] readBlock (int blockIndex)

读取16个字节的块。

这是一个I / O操作,将阻塞直到完成。 它不能从主应用程序线程调用。 如果从另一个线程调用close()被阻止的呼叫将被IOException取消。

需要 NFC权限。

Parameters blockIndex int: index of block to read, starting from 0 Returns byte[] 16 byte block Throws TagLostException if the tag leaves the field IOException if there is an I/O failure, or the operation is canceled restore Added in API level 10 void restore (int blockIndex)

从值块复制到临时块。

这是一个I / O操作,将阻塞直到完成。 它不能从主应用程序线程调用。 如果从另一个线程调用close()被阻止的呼叫将被取消, IOException 。

需要 NFC权限。

Parameters blockIndex int: index of block to copy from Throws TagLostException if the tag leaves the field IOException if there is an I/O failure, or the operation is canceled sectorToBlock Added in API level 10 int sectorToBlock (int sectorIndex)

返回给定扇区的第一个块。

不会导致任何RF活动并且不会阻止。

Parameters sectorIndex int: index of sector to lookup, starting from 0 Returns int block index of first block in sector setTimeout Added in API level 14 void setTimeout (int timeout)

以毫秒为单位设置 transceive(byte[])超时。

超时仅适用于此对象上的 transceive(byte[]) ,并在 close()时重置为默认值。

在标签上执行需要较长处理时间的事务(例如密钥生成)时,设置较长的超时时间可能很有用。

需要 NFC权限。

Parameters timeout int: timeout value in milliseconds transceive Added in API level 10 byte[] transceive (byte[] data)

将原始NfcA数据发送到标签并接收响应。

这相当于通过NfcA连接到此标签并致电transceive(byte[]) 。 请注意,所有MIFARE Classic标签都基于NfcA技术。

使用 getMaxTransceiveLength()检索可以与发送的字节的最大数量 transceive(byte[]) 。

这是一个I / O操作,将阻塞直到完成。 它不能从主应用程序线程调用。 如果从另一个线程调用close()被阻止的呼叫将被取消, IOException 。

需要 NFC权限。

Parameters data byte Returns byte[] Throws IOException

也可以看看:

transceive(byte[]) transfer Added in API level 10 void transfer (int blockIndex)

从临时块复制到值块。

这是一个I / O操作,将阻塞直到完成。 它不能从主应用程序线程调用。 如果从另一个线程调用close()被阻止的呼叫将被取消, IOException 。

需要 NFC权限。

Parameters blockIndex int: index of block to copy to Throws TagLostException if the tag leaves the field IOException if there is an I/O failure, or the operation is canceled writeBlock Added in API level 10 void writeBlock (int blockIndex, byte[] data)

写16个字节的块。

这是一个I / O操作,将阻塞直到完成。 它不能从主应用程序线程调用。 如果从另一个线程调用close()被阻止的呼叫将被IOException取消。

需要 NFC权限。

Parameters blockIndex int: index of block to write, starting from 0 data byte: 16 bytes of data to write Throws TagLostException if the tag leaves the field IOException if there is an I/O failure, or the operation is canceled


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有